//
//  SKMainTabVC.m
//  DaoJiaLe
//
//  Created by SprieaCT on 16/11/24.
//  Copyright © 2016年 Somer. All rights reserved.
//

#import "SKMainTabVC.h"
#import "SKJumpNav.h"
#import "UIImage+Render.h"

#import "SKHomeVC.h"
#import "SKIntroVC.h"
#import "SKBookVC.h"
#import "SKPersonVC.h"

#define versionKey @"CFBundleVersion"
@interface SKMainTabVC ()

@end

@implementation SKMainTabVC

#pragma mark - 设置tabBarItem的字体大小和颜色
+ (void)load
{

    UITabBarItem *item = [UITabBarItem appearance];
    NSDictionary *colorDict = @{
                                NSForegroundColorAttributeName : [UIColor blueColor]
                                };

    [item setTitleTextAttributes:colorDict forState:UIControlStateSelected];//***注意方法

}

- (void)viewDidLoad{
    [super viewDidLoad];
    //    self.fd_interactivePopDisabled = YES;
    //    [self getCurrVersion];
    [self setUpChildViewController];
    [self setUpAllTabBarItem];
}

- (void)getCurrVersion {
    //    NSString *versionPlist = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    //    NSString *urlStr = [NSString stringWithFormat:@"%@/common/checkversion", kDaoJiaLeUrl];
    //    NSDictionary *params = @{
    //                             @"version" : versionPlist,
    //                             @"type"    : @"ios"
    //                             };
    //    [SKHttpTool post:urlStr params:params success:^(id responseObj) {
    //        SKLog(@"%@",responseObj);
    //        if ([responseObj[@"code"] floatValue] == 200) {
    //            // 有最新版本
    //                NSString *version = responseObj[@"data"][@"aversion"];
    ////                [[NSUserDefaults standardUserDefaults] setObject:version forKey:versionKey];
    ////                [[NSUserDefaults standardUserDefaults] synchronize];
    //                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"发现新版本" message:version preferredStyle:UIAlertControllerStyleAlert];
    //                UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    //                UIAlertAction *update = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    //                    [[UIApplication sharedApplication] openURL: [ NSURL URLWithString:@"https://itunes.apple.com/cn/app/dao-jia-le-gou-fang-bao/id1190785005?mt=8"]];
    //                }];
    //                [alert addAction:cancle];
    //                [alert addAction:update];
    //                [self presentViewController:alert animated:YES completion:nil];
    //        }
    //    } failure:^(NSError *error) {
    ////        [SVProgressHUD showErrorWithStatus:@"服务器连接错误"];
    //    }];
    
    
}

#pragma mark - 设置子控制器
- (void)setUpChildViewController
{
    //首页
    UIViewController *homePageVC = [[SKHomeVC alloc] init];
    SKJumpNav *homePageNavC = [[SKJumpNav alloc] initWithRootViewController:homePageVC];
    [self addChildViewController:homePageNavC];
    
    
    //介绍
    UIViewController *hotPageVC = [[SKIntroVC alloc] init];
    SKJumpNav *hotPageNav = [[SKJumpNav alloc] initWithRootViewController:hotPageVC];
    [self addChildViewController:hotPageNav];
    
    
    //预定
    SKBookVC *messageVC = [[SKBookVC alloc] init];
    SKJumpNav *messageNavC = [[SKJumpNav alloc] initWithRootViewController:messageVC];
    [self addChildViewController:messageNavC];
    
    //我的
    SKPersonVC *mePageVC = [[SKPersonVC alloc] init];
    SKJumpNav *mePageNavC = [[SKJumpNav alloc] initWithRootViewController:mePageVC];
    [self addChildViewController:mePageNavC];
    
}

#pragma mark - 设置tabBar的各按钮的图片和文字
- (void)setUpAllTabBarItem
{
    SKJumpNav *homePage = self.childViewControllers[0];
    homePage.tabBarItem.title = @"首页";
    homePage.tabBarItem.image = [UIImage imageNamed:@"img23"];
    homePage.tabBarItem.selectedImage = [UIImage imageNameOfOriginal:@"img27"];
    
    
    SKJumpNav *InTro = self.childViewControllers[1];
    InTro.tabBarItem.title = @"介绍";
    InTro.tabBarItem.image = [UIImage imageNamed:@"img24"];
    InTro.tabBarItem.selectedImage = [UIImage imageNameOfOriginal:@"img28"];
    
    
    SKJumpNav *Book = self.childViewControllers[2];
    Book.tabBarItem.title = @"预定";
    Book.tabBarItem.image = [UIImage imageNamed:@"img25"];
    Book.tabBarItem.selectedImage = [UIImage imageNameOfOriginal:@"img29"];
    
    SKJumpNav *mePage = self.childViewControllers[3];
    mePage.tabBarItem.title = @"我的";
    mePage.tabBarItem.image = [UIImage imageNamed:@"img26"];
    mePage.tabBarItem.selectedImage = [UIImage imageNameOfOriginal:@"img30"];
    
}

@end

